
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="http://i.irenren.net//jquery-1.8.0.min.js"></script>
</head>
<body>
<div>每行的字符数:<input id="line-nums" value="58"></div>
<textarea id="t1" style="width: 600px; height:600px;">

</textarea>

<div style="float:left; width:600px;">result:<pre id="show"></pre></div>

<div><button id="commit">转换</button></div>

<script>
    $('#commit').click(function(){
        var content = $('#t1').val();

        var c = content.split("\n")
        var eng = {};
        var q;
        var line_nums = parseInt($('#line-nums').val(),10)
        if(line_nums == false){
            line_nums = 58
        }
        for(var i=0; i< c.length; i++){
            var text = c[i];


                if(!/[\u4e00-\u9fa5]/.test(text)){
                    if((q=/^([ A-Z]+?.+?):([\s\S]+)/.exec(text)) !== null ){
                        if(q[1] != 'CHARACTERS' && !/^[ ]*?\(.*?\)[ .]*?$/.test(q[2])){
                            console.log(q[0])
                            var names = q[1].split(",")
                            for(var uu=0; uu<names.length; uu++){
                                var nn = names[uu];
                                if(nn.replace(" ", "") == ""){
                                    continue
                                }
                                nn = $.trim(nn)
                                eng[nn]=(eng[nn]||0)+(
                                                (Math.ceil (
                                                        (q[0]).length / line_nums
                                                ))
                                        )
                            }


                        }
                    }
                }



        }

        var keys = Object.keys(eng)
        keys = keys.sort();

        var htmlstr = '';
        for(var k=0; k<keys.length; k++){
            htmlstr += "\n"+keys[k]+": "+eng[keys[k]]+'行';


        }



        $('#show').text(htmlstr);



    })

</script>

</body>
</html>
